package cn.itsource.controller.app;

import cn.itsource.pojo.app.bo.ConfirmBo;
import cn.itsource.pojo.app.vo.*;
import cn.itsource.pojo.vo.DriverLocationVo;
import cn.itsource.pojo.vo.SharedDriverLocationVo;
import cn.itsource.result.R;
import cn.itsource.service.IOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * 📖：beishan
 * 🗓️：2024/4/13 17:35
 * =====================
 */
@RestController
@RequestMapping("/app/driver")
public class DriverController {

    @Autowired
    private IOrderService orderService;


    @Operation(summary = "账单发送", description = "账单发送")
    @PostMapping("/send/{orderNo}")
    public R send(@PathVariable String orderNo) {
        orderService.send(orderNo);
        return R.success();
    }

    @Operation(summary = "账单详情", description = "账单详情")
    @GetMapping("/orderbill/{orderNo}")
    public R orderBill(@PathVariable String orderNo) {
        DriverBillVo billVo = orderService.orderBill(orderNo);
        return R.success(billVo);
    }

    @Operation(summary = "确认费用", description = "确认费用")
    @PostMapping("/confirm")
    public R confirm(@RequestBody ConfirmBo ConfirmBo) {
        orderService.confirm(ConfirmBo);
        return R.success();
    }

    @Operation(summary = "结束代驾", description = "结束代驾")
    @PostMapping("/enddriving/{orderNo}")
    public R endDriving(@PathVariable String orderNo) {
        BigDecimal allAmount = orderService.endDriving(orderNo);
        return R.success(allAmount);
    }

    @Operation(summary = "开始代驾", description = "开始代驾")
    @PostMapping("/startdriving/{orderNo}")
    public R startDriving(@PathVariable String orderNo) {
        orderService.startDriving(orderNo);
        return R.success();
    }

    @Operation(summary = "拉取位置", description = "拉取位置")
    @GetMapping("/pulllocation/{orderNo}")
    public R pullDriverLocation(@PathVariable String orderNo) {
        SharedDriverLocationVo sharedDriverLocationVo = orderService.pullDriverLocation(orderNo);
        return R.success(sharedDriverLocationVo);
    }

    @Operation(summary = "司机位置改变", description = "司机位置改变")
    @PostMapping("/location")
    public R location2driver(@PathVariable DriverLocationVo driverLocationVo) {
        orderService.location2driver(driverLocationVo);
        return R.success();
    }

    @Operation(summary = "司机到达代驾点", description = "司机到达代驾点")
    @PostMapping("/arrive/{orderNo}")
    public R arrive2driver(@PathVariable String orderNo) {
        orderService.arrive2driver(orderNo);
        return R.success();
    }

    @Operation(summary = "订单信息回显", description = "订单信息回显")
    @PostMapping("/execute")
    public R execute() {
        ExecuteOrderVo executeOrderVo = orderService.execute();
        return R.success(executeOrderVo);
    }

    @Operation(summary = "司机抢单", description = "司机抢单")
    @PostMapping("/kill/{id}")
    public R killOrder(@PathVariable("id") String id) {
        orderService.killOrder(id);
        return R.success();
    }


    @Operation(summary = "司机拉取订单", description = "司机拉取订单")
    @PostMapping("/pull")
    public R pull2Order() {
        List<CreateOrderVo> createOrderVoList = orderService.pull2Order();
        return R.success(createOrderVoList);
    }
}
